package com.lagou.service.impl;

import com.lagou.dubbo.service.IEmailService;
import com.lagou.util.EmailUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

@Service
@Component
@RefreshScope
public class EmailServiceImpl implements IEmailService {

    @Value("${config.email.host}")
    private String mailHost;

    @Value("${config.email.sender.name}")
    private String mailFrom;

    @Value("${config.email.sender.password}")
    private String mailFromPassword;

    @Override
    public boolean sendEmail(String mailTo, String mailTitle, String message) {
        try {
            EmailUtils.sendEmail(mailHost, mailFrom, mailFromPassword, mailTo, mailTitle, message);
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        } finally {
        }
    }
}
